package com.phkj.simple;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

/**
 * @description 发送方
 * @param
 * @return
 * @author wlj
 * @date 2018/9/5 10:32
 */
public class Send {
  private final static String QUEUE_NAME = "simple-example";

  public static void main(String[] argv)throws Exception {
      ConnectionFactory factory = new ConnectionFactory();
      factory.setHost("localhost");
      Connection connection = factory.newConnection();
      // 从连接中创建通道
      Channel channel = connection.createChannel();
    // 声明（创建）队列
      channel.queueDeclare(QUEUE_NAME, false, false, false, null);
      // 消息内容
      String message = "Hello World!";
      channel.basicPublish("", QUEUE_NAME, null, message.getBytes());
      System.out.println(" 后端系统发送信息 '" + message + "'");
      //关闭通道和连接
      channel.close();
      connection.close();
  }
}  